timer=0;
aniqueue=[];
window.onload=function(){setInterval("tick()",100);}

function tick(){
  timer++;
  for(i=0;i<aniqueue.length;i++) {
    if(aniqueue[i].finished()) {aniqueue.splice(i,1);} 
    else {aniqueue[i].animate();aniqueue[i].time++;}          
  }
}
     
function animate(f) {
  aniqueue.push(f);
}
      
function debug(text) {
  dbg=document.getElementById("debug");
  if(dbg!=null) {
    dbg.innerHTML+=text;
  }
}

function aniobj() {
  this.time=0;
  this.animate=function(){};
  this.finished=function(){return false};
}
      
function Message(elemId,msgarray,delay) {
  obj=new aniobj();
  obj.delay=delay;
  obj.msgarray=msgarray;
  obj.animate=function(){
    container=document.getElementById(elemId);
    container.innerHTML=this.msgarray[Math.floor(this.time/this.delay)%this.msgarray.length];
  }
  obj.finished=function(){
    if(this.time>=(this.msgarray.length*this.delay)) {return true;}
    else {return false;}
  }
  return obj;
}

function Flash(elemId) {
  obj=new aniobj();
  obj.delay=3;
  obj.animate=function(){
    container=document.getElementById(elemId);
    if(Math.floor(this.time/this.delay)%2==0) {
      container.style.visibility="visible";
    } else {
      container.style.visibility="hidden";
    }
  }
  obj.finished=function(){
    //if(this.time>=(this.msgarray.length*this.delay)) {return true;}
    //else {return false;}
  }
  return obj;
}

function ColorChanger(elemId,colors) {
  obj=new aniobj();
  obj.delay=4;
  obj.colors=colors;
  obj.animate=function(){
    container=document.getElementById(elemId);
    color=this.colors[Math.floor(this.time/this.delay)%this.colors.length];
    container.style.color=color;
    container.style.borderColor=color;
  }
  return obj;
}
